/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import pojo.ThamSoPOJO;

/**
 *
 * @author b2
 */
public class ThamSoDAO {

    public static ThamSoPOJO layDanhSahThamSO() {

        ThamSoPOJO ts = new ThamSoPOJO();
        try {
            String sql = "SELECT * FROM THAMSO";
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while (rs.next()) {
                ts.setSoSanBayTrungGianToiDa(rs.getInt("SoSanBayTrungGianToiDa"));
                ts.setTGChamNhatDatVe(rs.getInt("TGChamNhatDatVe"));
                ts.setTGChamNhatHuyDatVe(rs.getInt("TGChamNhatHuyDatVe"));
                ts.setThoiGianBayToiThieu(rs.getInt("ThoiGianBayToiThieu"));
                ts.setThoiGianDungToiDa(rs.getInt("ThoiGianDungToiDa"));
                ts.setThoiGianDungToiThieu(rs.getInt("ThoiGianDungToiThieu"));
            }
            helper.close();
        } catch (SQLException ex) {
            Logger.getLogger(ThamSoDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ts;
    }

    public static boolean updateThamSo(int thoigianBayToiThieu, int SBTrungGianToiDa, int TGDungToiThieu, int TGDungToiDa) {
        boolean kq = false;
        String sql = "UPDATE THAMSO SET ThoiGianBayToiThieu = '" + thoigianBayToiThieu + "' ,SoSanBayTrungGianToiDa = '" + SBTrungGianToiDa + "', ThoiGianDungToiThieu = '" + TGDungToiThieu + "', ThoiGianDungToiDa ='" + TGDungToiDa + "'";
        MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
        helper.open();
        int n = helper.executeUpdate(sql);
        if (n == 1) {
            kq = true;
        }
        helper.close();

        return kq;
    }

    public static boolean updateHuyVeDatVe(int tgDat, int tgHuy) {
        boolean kq = false;
        String sql = "UPDATE THAMSO SET TGChamNhatDatVe = '" + tgDat + "' ,TGChamNhatHuyDatVe = '" + tgHuy + "'";
        MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
        helper.open();
        int n = helper.executeUpdate(sql);
        if (n == 1) {
            kq = true;
        }
        helper.close();

        return kq;
    }
}
